package com.wellink.simpleadapterdemo;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class SimpleAdapterActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.simpleadapter_layout);

        ListView listView = findViewById(R.id.listview);

        SimpleAdapter adapter = new SimpleAdapter(this,getData(),R.layout.simpleadapter_item,
                new String[]{"img","title","info"},new int[]{R.id.img,R.id.title,R.id.info});

        listView.setAdapter(adapter);
    }

    protected List<Map<String,Object>> getData(){
        List<Map<String,Object>> list = new ArrayList<>();

        Map<String,Object> map = new HashMap<>();
        map.put("img",R.drawable.icon1);
        map.put("title","Veikin");
        map.put("info","Develop");
        list.add(map);

        map=new HashMap<>();
        map.put("img", R.drawable.icon2);
        map.put("title", "貂蝉");
        map.put("info", "四大美女");
        list.add(map);

        map = new HashMap<>();
        map.put("img", R.drawable.icon3);
        map.put("title", "奶茶");
        map.put("info", "清纯妹妹");
        list.add(map);

        map = new HashMap<>();
        map.put("img", R.drawable.icon4);
        map.put("title", "大黄");
        map.put("info", "是小狗");
        list.add(map);

        map = new HashMap<>();
        map.put("img", R.drawable.icon5);
        map.put("title", "hello");
        map.put("info", "every thing");
        list.add(map);

        map = new HashMap<>();
        map.put("img", R.drawable.icon6);
        map.put("title", "world");
        map.put("info", "hello world");
        list.add(map);

        return list;
    }
}
